package yunjiao.javatutorials.designpatterns.interpreter;

import lombok.extern.slf4j.Slf4j;

import java.util.HashMap;
import java.util.Map;

/**
 * 入口
 *
 * @author yangyunjiao
 */
@Slf4j
public class App {
    public static void main(String[] args) {
        // Define the expression: x + (y - 2)
        Expression expression = new NonTerminalExpression.AddExpression(
                new TerminalExpression.VariableExpression("x"),
                new NonTerminalExpression.SubtractExpression(
                        new TerminalExpression.VariableExpression("y"),
                        new TerminalExpression.ConstantExpression(2)
                )
        );

        Map<String, Integer> context = new HashMap<>(2);
        for(int x = 0; x < 10; x++) {
            for(int y = 0; y < 10; y++) {
                context.clear();
                context.put("x", x);
                context.put("y", y);
                log.info("When: x={}, y={} Result: {}", x, y, expression.interpret(context));
            }
        }

    }
}
